package cc.gu.tank.sprite;

import javafx.geometry.Rectangle2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;

/**
 * @Author: GuSongLiao
 * @Date: 2025/9/29 9:59
 * @Description: 精灵类，所有元素父类
 */

public abstract class Sprite {

    protected double x, y, width, height;

    protected Image image;

    protected boolean alive = true;

    public Sprite(Image image, double x, double y, double width, double height) {
        this.image = image;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    public void draw(GraphicsContext graphicsContext2D) {
        graphicsContext2D.drawImage(image, x, y, width, height);
    }

    public boolean isAlive() {
        return alive;
    }

    /**
     * 获取控制区域, 用于碰撞检测
     * @return
     */
    public Rectangle2D getController() {
        return new Rectangle2D(x, y, width, height);
    }



}
